package com.weetop.cfw.base.presenter.imp

import com.weetop.cfw.base.presenter.CloudCurriculumPresenter
import com.weetop.cfw.base.view.BaseView
import com.weetop.cfw.base.view.CloudCurriculumView
import com.weetop.cfw.bean.AudioVideoBrowsingRecordBean
import com.weetop.cfw.bean.AudioVideoFilterBean
import com.weetop.cfw.callback.RxJavaCallBack
import com.weetop.cfw.mine.activity.CloudCurriculumActivity
import com.weetop.cfw.utils.RetrofitUtils
import com.weetop.cfw.utils.RxJavaUtils

class CloudCurriculumPresenterImp(var cloudCurriculumView: CloudCurriculumView? = null): CloudCurriculumPresenter {


    /**
     * 获取云课程筛选分类数据
     */
    override fun getCloudCurriculumFilterData(cloudCurriculumActivity: CloudCurriculumActivity) {
        RxJavaUtils.useInAppCompatActivityOnDestory(RetrofitUtils.getApi().getVideoFilterData(),cloudCurriculumActivity,object:RxJavaCallBack<AudioVideoFilterBean>(){
            override fun onSuccess(t: AudioVideoFilterBean?) {
                cloudCurriculumView?.getCloudCurriculumFilterDataSuccess(t)
            }
        })
    }

    /**
     * 获取云课程数据列表
     */
    override fun getCloudCurriculumDataList(cloudCurriculumActivity: CloudCurriculumActivity, classid: Int, key: String, curpage: Int) {
        cloudCurriculumActivity.showLoadingDialog(cloudCurriculumActivity,"正在获取云课程列表数据...")
        RxJavaUtils.useInAppCompatActivityOnDestory(RetrofitUtils.getApi().getVideoListData(classid = classid,Key = key,curpage = curpage),cloudCurriculumActivity,object:RxJavaCallBack<AudioVideoBrowsingRecordBean>(){
            override fun onSuccess(t: AudioVideoBrowsingRecordBean?) {
                cloudCurriculumActivity.dismissLoadingDialog()
                cloudCurriculumView?.cloudCurriculumListDataGetSuccess(t)
            }

            override fun onRequestError(t: AudioVideoBrowsingRecordBean?) {
                super.onRequestError(t)
                cloudCurriculumActivity.dismissLoadingDialog()
                cloudCurriculumView?.cloudCurriculumListDataGetFailed()
            }

            override fun onErrorResponse(throwable: Throwable?) {
                super.onErrorResponse(throwable)
                cloudCurriculumActivity.dismissLoadingDialog()
                cloudCurriculumView?.cloudCurriculumListDataGetFailed()
            }

        })
    }


    /**
     * 绑定
     */
    override fun attachView(baseView: BaseView) {
        cloudCurriculumView = baseView as? CloudCurriculumView
    }

    /**
     * 解绑
     */
    override fun detachView() {
        cloudCurriculumView = null
    }
}